//
//  MianTypeListNextPageViewController.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/11.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "MianTypeListNextPageViewController.h"
#import "MyStoreInformationViewController.h"

@interface MianTypeListNextPageViewController ()
@property (nonatomic, strong) MianTypeListNextPageViewModel *viewModel;

@end

@implementation MianTypeListNextPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNavigationItemWithImageNames:@[@"jiantou"] isLeft:YES target:self action:@selector(leftAction:) tags:@[@1112]];
    self.viewModel = [[MianTypeListNextPageViewModel alloc] initWithViewToViewModel:self.tableView theSuperView:self.view];
    self.viewModel.type = self.type;
    self.viewModel.dic = [NSMutableDictionary dictionaryWithDictionary:self.dic];

    kWeakSelf(self);
    self.viewModel.BlockSelectRow = ^(NSDictionary *dic) {
        if (weakself.type == ChooseType_Main) {
            [weakself seleRow:dic];
        } else {
            [weakself doneAction:dic];
        }
    };
}
// 跳转到下一页
- (void)seleRow:(NSDictionary *)dic
{
    MianTypeListNextPageViewController *vc = [MianTypeListNextPageViewController new];
    vc.title = @"主要钢厂";
    vc.dic = [NSMutableDictionary dictionaryWithDictionary:dic];
    vc.type = ChooseType_SteelMills;
    [self.navigationController pushViewController:vc animated:YES];
}

// 点击完成，跳转到我的资料店铺页面
- (void)doneAction:(NSDictionary *)dic
{
//    DLog(@"完成跳转:%@", dic);
    for (UIViewController *vc in self.rt_navigationController.rt_viewControllers) {
        if ([vc isKindOfClass:[MyStoreInformationViewController class]]) {
            MyStoreInformationViewController *mainVC = (MyStoreInformationViewController *)vc;
            [self.navigationController popToViewController:mainVC animated:YES];
            KPostNotification(@"kMainTypeList", dic);
        }
    }
}

- (void)leftAction:(GLGWButton *)sender
{
    if (self.type == ChooseType_Main) {
        if (self.viewModel.dic[@"two"]) {  // 点击了下一步
            if (self.BlockBackPage) {
                self.BlockBackPage(self.viewModel.dic);
            }
        }
    }
    [self.navigationController popViewControllerAnimated:YES];
}

@end
